#include "../source/server.hpp"


void OnConnected(const PtrConnection& conn)
{
    DBG_LOG("NEW CONNECTION:%p", conn.get());
}
void OnClosed(const PtrConnection& conn)
{
    DBG_LOG("CLOSE CONNECTION:%p", conn.get());
}
void OnMessage(const PtrConnection& conn, Buffer* buf)
{
    DBG_LOG("%s", buf->ReadPosition());
    buf->MoveReadOffset(buf->ReadAbleSize());
    std::string str = "Hello World";
    conn->Send(str.c_str(), str.size());
    // conn->Shutdown();
}

int main()
{
    TcpServer server(8085);
    server.SetThreadCount(2);
    server.EnableInactiveRelease(10);
    server.SetConnectedCallback(OnConnected);   //这就和std::bind(_1_2)一样，个数和类型并没有和定义的函数有冲突的地方，所以不需要bind预留的方式
    server.SetMessageCallback(OnMessage);
    server.Start();
    return 0;
}